/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.blitzcoder.collide.gui.fileexplorer;

import de.blitzcoder.collide.Config;
import java.awt.GridLayout;
import java.io.File;
import java.util.Arrays;
import java.util.Enumeration;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

/**
 *
 * @author blitzcoder
 */
public class FileExplorer extends JPanel {

    private FileTree tree;
    private FileTable list;
    
    public FileExplorer() {
        
        setLayout(new GridLayout());
        
        /* |-----|
         * |Tree |
         * |     |
         * |-----|
         * |List |
         * |     |
         * |-----|
         */
        
        JSplitPane splitPane = new JSplitPane();
        
        list = new FileTable();
        tree = new FileTree(list);


        // Set start-folder
        if (Config.getFileProperty("fileexplorer.lastpath") != null && Config.getFileProperty("fileexplorer.lastpath").exists()) {
            list.setDir(Config.getFileProperty("fileexplorer.lastpath"));

            String path = Config.getProperty("fileexplorer.lasttreepath");
            path = path.replace("]","");
            path = path.replace("[","");
            String[] pathArray = path.split(", ");
            TreePath treePath = new TreePath(pathArray);
            tree.expandPath(treePath);

        } else {
            if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) {
                // Workaround for Java-Bug #4787931 (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4787931)
                list.setDir(new File(System.getenv("USERPROFILE")));
            } else
                list.setDir(new File(System.getProperty("user.home")));
        }
        

        splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
        
        splitPane.setLeftComponent(new JScrollPane(tree));
        splitPane.setRightComponent(new JScrollPane(list));
        
        splitPane.setDividerLocation(200);
        
        add(splitPane);
        
    }
    
}
